package com.eyas.software.pattern.eventbus.event;

/**
 * Event对象，存储Event的类型和内容，以eventType作为Event类型区分的key
 * 因为register使用hashMap存储，需要重写hashcode和equals方法
 */
public class Event {
    //事件类型
    private Class<?> eventType;
    //事件内容
    private Object eventContent;

    public Class<?> getEventType() {
        return eventType;
    }

    public void setEventType(Class<?> eventType) {
        this.eventType = eventType;
    }

    public Object getEventContent() {
        return eventContent;
    }

    public void setEventContent(Object eventContent) {
        this.eventContent = eventContent;
    }

    public Event() {

    }

    public Event(Class<?> eventType,Object eventContent) {
        this.eventType = eventType;
        this.eventContent = eventContent;
    }

    @Override
    public int hashCode() {
        return this.eventType.hashCode();
    }

    @Override
    public boolean equals(Object object) {
        if(object==null)
            return false;
        if(object.getClass()!=this.getClass())
            return false;
        Event o = (Event)object;
        return o.getEventType() == this.getEventType();
    }
}
